package com.ss.android.article.common.e;

import android.content.Context;
import android.view.ViewGroup;

import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.feature.video.IVideoController;
import com.ss.android.common.util.Singleton;

import java.util.EnumSet;

public class VideoControllerSupplierProxy implements IVideoControllerSupplier {
    private static final String TAG = VideoControllerSupplierProxy.class.getSimpleName();
    private static Singleton<VideoControllerSupplierProxy> singleton = new Singleton<VideoControllerSupplierProxy>() {
        @Override
        public final VideoControllerSupplierProxy create() {
            return new VideoControllerSupplierProxy();
        }
    };
    private IVideoControllerSupplier mVideoControllerSupplier;

    public VideoControllerSupplierProxy() {
    }

    public final IVideoController createVideoController(Context context, ViewGroup container, boolean arg4, EnumSet arg5) {
        this.ensureVideoControllerSupplier();
        return this.mVideoControllerSupplier == null ? null : this.mVideoControllerSupplier.createVideoController(context, container, arg4, arg5);
    }

    public final IVideoController createVideoController(Context context, ViewGroup container, boolean arg4) {
        this.ensureVideoControllerSupplier();
        return this.mVideoControllerSupplier == null ? null : this.mVideoControllerSupplier.createVideoController(context, container, arg4);
    }

    public final void releaseVideoControllerInstance() {
        this.ensureVideoControllerSupplier();
        if (this.mVideoControllerSupplier != null) {
            this.mVideoControllerSupplier.releaseVideoControllerInstance();
        }
    }

    public final IVideoController getVideoControllerInstance() {
        this.ensureVideoControllerSupplier();
        return this.mVideoControllerSupplier == null ? null : this.mVideoControllerSupplier.getVideoControllerInstance();
    }

    public final IVideoController createVideoControllerDirectly(Context context, ViewGroup container, boolean arg4, EnumSet arg5) {
        this.ensureVideoControllerSupplier();
        return this.mVideoControllerSupplier == null ? null : this.mVideoControllerSupplier.createVideoControllerDirectly(context, container, arg4, arg5);
    }

    public static VideoControllerSupplierProxy getInstance() {
        return singleton.get();
    }

    private void ensureVideoControllerSupplier() {
        if (this.mVideoControllerSupplier == null) {
            try {
                Object obj = Class.forName("com.ss.android.video.VideoControllerSupplier").newInstance();
                if (obj instanceof IVideoControllerSupplier) {
                    this.mVideoControllerSupplier = ((IVideoControllerSupplier) obj);
                }
            } catch (Throwable throwable) {
                Logger.d("module", "load " + VideoControllerSupplierProxy.TAG + " exception: " + throwable);
            }
        }
    }
}

